/*
day184
2020.2.28
*/
#include<iostream>
#include<vector>
#include<algorithm> 
using namespace std;

class Solution {
public:
    int findLongestChain(vector<vector<int>>& pairs) {
    	sort(pairs.begin(),
			pairs.end(),
			[](const vector<int> &vec1,const vector<int> &vec2)->bool{
				return vec1[1]<vec2[1];
			}
			);
    	int res=1;
    	int size=pairs.size();
		int *arr=(int *)malloc(sizeof(int)*size);
		arr[0]=1;
		for(int i=1;i<size;++i)
		{
			arr[i]=1;
			for(int j=0;j<i;++j)
			{
				if( pairs[j][1] < pairs[i][0] )
				{
					int tem=arr[j]+1;
					arr[i]=arr[i]>tem ? arr[i] : tem;
				}
			}
			res=res>arr[i] ? res : arr[i];
		}
		return res;
    }
};

int main()
{
	Solution s;
	vector<vector<int>> pairs={{3,4},{2,3},{1,2}};
	cout<<s.findLongestChain(pairs)<<endl;
	return 0;
}
